#pragma once
#include <iostream>
#include "protocol.hpp"

// 业务处理
class Calculate
{
public:
    Result Excute(const Request &req)
    {
        Result result;
        switch (req.get_op())
        {
        case 0:
            result.set_result(req.get_x() + req.get_y());
            result.set_code(0);
            break;
        case 1:
            result.set_result(req.get_x() - req.get_y());
            result.set_code(0);
            break;
        case 2:
            result.set_result(req.get_x() * req.get_y());
            result.set_code(0);
            break;
        case 3:
            if (req.get_y() == '0')
            {
                result.set_code(1);
                break;
            }
            result.set_result(req.get_x() / req.get_y());
            result.set_code(0);
            break;
        default:
            result.set_code(3); // 非法操作
            break;
        }
        return result;
    }
};